package com.shop.loan.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shop.loan.mapper.LoanOrderByMybatisMapper;
import com.shop.loan.model.entity.LoanOrderByMybatis;
import com.shop.loan.model.vo.LoanOrderByUnBankAllotVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import xyz.erupt.annotation.fun.OperationHandler;

import javax.annotation.Resource;
import java.util.List;

/**
 * 待绑卡列表分配
 */
@Slf4j
@Service
public class LoanOrderByUnBankAllotHandler implements OperationHandler<Object, LoanOrderByUnBankAllotVo> {

    @Resource
    LoanOrderByMybatisMapper loanOrderByMybatisMapper;

    @Override
    public String exec(List<Object> data, LoanOrderByUnBankAllotVo loanOrderByUnBankAllotVo, String[] param) {
        for (Object item : data) {
            JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(item));
            LoanOrderByMybatis loanOrderByMybatis = new LoanOrderByMybatis();
            loanOrderByMybatis.setId(jsonObject.getLongValue("id"));
            loanOrderByMybatis.setAuthServiceId(loanOrderByUnBankAllotVo.getAuthServiceUser().getId());
            loanOrderByMybatisMapper.updateByPrimaryKeySelective(loanOrderByMybatis);
        }
        return null;
    }
}
